package Io;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;

public class TwoFile
{
	public static void main(String[] args)
	{
		System.out.println("========");
//		writeFile();
		File start = new File("D:/Sublime Text_3176.zip");
		File end  = new File("D:/a/q_1b/Sublime Text_31761.zip");
		copyFile(start,end);
	}

	private static void copyFile(File start, File end)
	{
		long a = System.currentTimeMillis();
		int len  = 0;
		FileInputStream fos = null;
		FileOutputStream fas = null;
		try
		{
			byte [] b = new byte[1024];
			fos = new FileInputStream(start);
			fas = new FileOutputStream(end);
			while(( len = fos.read(b)) != -1)
			{
//				System.out.println(len + "==>"+Arrays.toString(b));
				fas.write(b, 0, len);
			}			
			fas.flush();
			
		} catch (FileNotFoundException e)
		{
			e.printStackTrace();
		} catch (IOException e)
		{
			e.printStackTrace();
		}catch (Exception e)
		{
			e.printStackTrace();
		}finally 
		{
			try
			{
				if(fos != null)
				{
					fos.close();
					fos = null;
				}
				
			} catch (IOException e)
			{
				e.printStackTrace();
			}
		}
		long b = System.currentTimeMillis();
		System.out.println("耗时=>"+(b-a));
	}

	private static void writeFile()
	{
		String path = "D:" + File.separator + "a" + File.separator + "c.txt";
		System.out.println(path);
		File ff = new File(path);
		FileOutputStream fos = null;
		try
		{
			byte [] b = "大壮\r\n".getBytes();
			fos = new FileOutputStream(ff,true);
			fos.write(b);

		} catch (FileNotFoundException e)
		{
			e.printStackTrace();
		} catch (IOException e)
		{
			e.printStackTrace();
		} 
		catch (Exception e)
		{
			e.printStackTrace();
		} finally
		{
			try
			{
				if(fos != null)
				{
					fos.close();
					fos = null;
				}
				
			} catch (IOException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
